<template>

  <el-container style="min-height: 100vh; border:1px solid #eee">
    <!--侧边栏-->
    <el-aside class="el-aside" style="background-color: rgb(238, 241, 246); box-shadow: 2px 0 6px rgb(0 21 41 / 35%)"
              :width="sideWidth + 'px' ">
      <Aside :isCollapse="isCollapse" :logoTextShow="logoTextShow"/>
    </el-aside>
    <!--右边主体-->
    <el-container>
      <!--主体头部-->
      <el-header style="border-bottom: 1px solid #ccc;">
        <Header :collapseBtnClass="collapseBtnClass" :collapse="collapse" :user="user"/>
      </el-header>
      <!--主体内容-->
      <el-main>
        <!--表示当前页面的子路由会在 router-view里展示-->
        <router-view @refreshUser="getUser"/>
      </el-main>
    </el-container>
  </el-container>

</template>

<script>


import Aside from "@/components/Aside";
import Header from "@/components/Header";

export default {
  name: 'Home',
  components: {Aside, Header},
  data() {
    return {
      sideWidth: 200,
      collapseBtnClass: "el-icon-s-fold",
      logoTextShow: true,
      isCollapse: false,
      user: {}
    }
  },
  created() {
    // 从后台获取数据
    this.getUser()
  },
  methods: {
    collapse() { // 点击导航栏收缩按钮触发
      this.isCollapse = !this.isCollapse
      if (this.isCollapse) {
        this.sideWidth = 64
        this.collapseBtnClass = 'el-icon-s-unfold'
        this.logoTextShow = false
      } else {
        this.sideWidth = 200
        this.collapseBtnClass = 'el-icon-s-fold'
        this.logoTextShow = true
      }
    },
    getUser() {
      let username = localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")).username : {}
      // 从后台获取数据
      this.request.get("/user/username/" + username).then((res) => {
        // 重新赋值
        this.user = res.data
      })
    }
  }
}
</script>

<style scoped>
.el-header {
  /*background-color: #B3C0D1;*/
  /*color: #333;*/

}

.el-aside {
  color: #333;
}

</style>